#!/bin/bash

# Set the installation directory from the first argument, or default to the user's home directory.
INSTALL_DIR="${1:-$HOME}"

# Define the source directory, which is the .gemini directory in the same location as this script.
SOURCE_DIR="$(dirname "$0")/.gemini"

# Define the target .gemini directory.
TARGET_DIR="$INSTALL_DIR/.gemini"

# Check if the source .gemini directory exists.
if [ ! -d "$SOURCE_DIR" ]; then
  echo "Error: Source directory not found at $SOURCE_DIR"
  exit 1
fi

# Create the target directory if it doesn't exist.
mkdir -p "$TARGET_DIR"

# Use rsync to merge the contents of the source directory into the target directory.
# -a is for archive mode (preserves permissions, ownership, etc.)
# -v is for verbose output.
rsync -av "$SOURCE_DIR/" "$TARGET_DIR/"

echo "Installation complete. .gemini has been merged into $TARGET_DIR"
